<?php
class Api_Lib_Rsp_Department {

    function __construct() {
        $this->_modelExample = FLEA::getSingleton('Model_Jichu_Department');
    }

    /**
     *
     * Time：2019/11/07 14:01:47
     * @author li
     * @param 参数类型
     * @return 返回值类型
    */
    function update($params,& $service){
        if(!$params['depName']){
            $service->send_user_error('depName required');
        }

        //检查是否存在
        $department = $this->_modelExample->find(array('depName'=>$params['depName']));


        $_data = array(
            'id'      => $department['id']+0,
            'depName' => $params['depName'],
        );

        //数据保存
        $result = $this->_modelExample->save($_data);
        $department['id'] = $department['id'] ? $department['id'] : $result;

        return array('success'=>$result ? true :false ,'msg'=>'完成','data'=>array('id'=>$department['id']));
    }


    /**
     * 获取客户列表
     * Time：2019/11/07 15:09:10
     * @author li
     * @param 参数类型
     * @return 返回值类型
    */
    function getList($params,& $service){
        $pageNum     = $params['pageNum'] ? $params['pageNum'] : 50;
        $currentPage = $params['page'] ? $params['page'] : 1;

        $condition = array();
        if($params['depName']!='') {
            $condition[] = array('depName',"%{$params['depName']}%",'like');
        }

        // $this->_modelExample->clearLinks();
        FLEA::loadClass('TMIS_Pager');
        $pager = & new TMIS_Pager($this->_modelExample,$condition,'id desc',$pageNum ,($currentPage - 1));
        $rowset = $pager->findAll();
        //把需要的数据带出来
        $rows = array();
        foreach ($rowset as $key => & $v) {
            $rows[] = array(
                'id'      => $v['id'],
                'depName' => $v['depName'],
            );
        }

        return array('row'=>$rows,'page'=>$currentPage,'total'=>$pager->totalCount,'pageCount'=>count($rows));
    }
}
?>